package user

import (
	"APi/client"
	"APi/request"
	"APi/response"
	"github.com/gin-gonic/gin"
	user "user_srv/proto"
)

func ListUserCoupon(c *gin.Context) {
	userId := c.GetUint("userId")
	var data request.ListUserCouponRequest
	if err := c.ShouldBind(&data); err != nil {
		response.CurrencyErrResponse(c, 101, err.Error())
		return
	}
	if data.UserCouponStatus != "" && data.UserCouponStatus != "已过期" && data.UserCouponStatus != "未过期" && data.UserCouponStatus != "已使用" {
		response.CurrencyErrResponse(c, 101, "请输入合理的优惠券使用状态")
		return
	}
	res, err := client.UserCouponList(c, &user.UserCouponListRequest{
		Userid:           int64(userId),
		UserCouponStatus: data.UserCouponStatus,
	})
	if err != nil {
		response.CurrencyErrResponse(c, -1, err.Error())
		return
	}
	response.CurrencySuccessResponse(c, "查看自己的优惠券成功", map[string]interface{}{"my_coupon": res.AllUserCoupon})
}
